// components/nav-bottom/nav-bottom.js
var controlSignal = {
    homeTab: 1,
    courseTab: 0,
    meTab: 0,
    courseManageTab: 1,
    VIPTab: 0,
};

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    type: { // 属性名
      type: Number,
      value: 2
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    homeTab: 0,
    courseTab: 0,
    meTab: 0,
    courseManageTab: 0,
    VIPTab: 0,
    windowHeight:0
  },
  lifetimes:{
    attached: function() {
      wx.getSystemInfo({
        complete: (res) => {
          let windowHeight = res.windowHeight
          if(windowHeight){
            this.setData({
              windowHeight:windowHeight
            })
          }
        },
      })
      
    }

  },

  pageLifetimes: {
    
    show: function( ) {

      var currPages = getCurrentPages()
      var currPage = currPages[currPages.length -1]

      this.fitControlSignal(currPage.route)
      this.setData({
        homeTab: controlSignal.homeTab,
        courseTab: controlSignal.courseTab,
        meTab: controlSignal.meTab,
        courseManageTab : controlSignal.courseManageTab,
        VIPTab : controlSignal.VIPTab       
      })
      // 页面被展示
    },
  
  },

  /**
   * 组件的方法列表
   */
  methods: {
    navCourseManage(){
      if(!controlSignal.courseManageTab){
        wx.redirectTo({
          url: '../classManage/classManage',
        })
        this.setData({
          courseManageTab:1,
          VIPTab: 0
        })
        controlSignal.courseManageTab = 1
        controlSignal.VIPTab = 0
      }
      
    },
    navVIP(){
      if(!controlSignal.VIPTab){
        wx.redirectTo({
          url: '../VIPmanage/VIPmanage',
        })
        this.setData({
          courseManageTab: 0,
          VIPTab: 1
        })
        // controlSignal.courseManageTab = 0
        // controlSignal.VIPTab = 1
      }
     
    },
    navHome(){
      if(!controlSignal.homeTab){
        wx.redirectTo({
          url: '../home/home',
        })
        this.setData({
          homeTab: 1,
          courseTab: 0,
          meTab: 0,
        })
        // controlSignal.homeTab= 1
        // controlSignal.courseTab = 0
        // controlSignal.meTab = 0
      }
          
    },
    navCourse(){
      if(!controlSignal.courseTab){
        wx.redirectTo({
          url: '../course/course',
        })
        this.setData({
          homeTab: 0,
          courseTab: 1,
          meTab: 0,
        })
        // controlSignal.homeTab= 0
        // controlSignal.courseTab = 1
        // controlSignal.meTab = 0
      }
     
    },
    navMe(){
      if(!controlSignal.meTab){
        wx.redirectTo({
          url: '../me/me',
        })
        this.setData({
          homeTab: 0,
          courseTab: 0,
          meTab: 1,
        })
        // controlSignal.homeTab= 0
        // controlSignal.courseTab = 0
        // controlSignal.meTab = 1
      }
      
    },

    fitControlSignal(path){
        
      controlSignal.homeTab = 0
      controlSignal.courseTab = 0
      controlSignal.meTab = 0
      controlSignal.courseManageTab = 0
      controlSignal.VIPTab = 0

      switch(path){
        case "pages/VIPmanage/VIPmanage":{
          controlSignal.VIPTab = 1
          break;
        }
        case "pages/classManage/classManage":{
          controlSignal.courseManageTab = 1
          break;
        }
        case "pages/home/home":{
          controlSignal.homeTab = 1
          break;
        }
        case "pages/course/course":{
          controlSignal.courseTab = 1
          break;
        }
        case "pages/me/me":{
          controlSignal.meTab = 1
          break;
        }     
      }
    },
  },
  
})
